import {Result} from '@/base/Result';
import {request} from '@/base/Request';
import {Page} from '@/base/Page';
import {Banners} from '@/base/model/Banners';
import {Banner} from '@/base/model/Banner';
import qs from 'qs'
import {Wishes} from '@/base/model/Wishes';
import {WishesType} from '@/base/model/WishesType';

export function getBannersList(params: {
  pageIndex: number;
  pageSize: number;
  sortDirection: string;
  position: number;
  bannername?: string;
  companyname?: string;
  agentname?: string;
}): Promise<Result<Page<Banners>>> {

  return request.getPage(Banners, '/api/banner?', {params});
}

export function getBanners(bannerId: number): Promise<Result<Banner>> {
  return request.get(Banner, `/api/banner/${bannerId}`);
}
export function getProductName(params:{modelId}): Promise<Result<String>> {
  return request.get(String, '/api/mall/getModelName?', {params});
}
export function deleteBanners(bannerid: number): Promise<Result<void>> {
  return request.delete(`/api/banner/${bannerid}`);
}

export function putbanner(params: {
  bannerId:number,
  agentId: number,
  bannername:string,
  companyId: number,
  imageurl: string,
  status: number,
  position:number,
  actions?: number,
  linkurl?:string,
  linkurlWebview?:string,
  sort?: number,
  endTime?:String,
  startTime?:String
}) {
  return request.put(Banner, '/api/banner/update', qs.stringify(params));
}

export function PutBannerId(params: {
  bannerId: number,
  status: number,
}) {
  return request.put(Banners, `/api/banner/${params.bannerId}`, qs.stringify(params))
}

export function postBanner(params: {
  agentId: number,
  bannername: string,
  companyId: number,
  imageurl: string,
  position: number,
  status: number,
  linkurl?: string,
  linkurlWebview?: string,
  actions?: number,
  sort?: number,
  startTime?:String,
  endTime?:String
}) {
  return request.post(Banners, `api/banner`, qs.stringify(params));
}
export function getWishesList(params: {
  pageIndex: number;
  pageSize: number;
  sortDirection: string;
  wishName?: string;
  companyName?: string;
  agentName?: string;
  phone?:string
}): Promise<Result<Page<Wishes>>> {
  return request.getPage(Wishes, '/api/banner/fetchWishes', {params});
}
export function PutWishes(params: {
  isAble: number,
  wishId: number,
}) {
  return request.put(Wishes, `/api/banner/updateWishesStatus`, qs.stringify(params))
}
// export function postWishes(params: NewsVM): Promise<Result<News>> {
//   let formData = new FormData();
//   Object.keys(params).forEach(x => {
//     formData.append(x, params[x]);
//   });
//   return request.post(News, '/api/news', formData);
// }
export function postWishes(params: {
  agentId: number,
  wishName: string,
  companyId: number,
  wishUrl: any,
  isAble: number,
  memberIds: [],
  type: string,
  startTime?:Number,
  endTime?:Number,
  screenOpeningTime:number,
  linkUrl:string,
  isAll:number,
}): Promise<Result<Wishes>> {
  // console.log(params);
  // let formData = new FormData();
  // Object.keys(params).forEach(x => {
  //   formData.append(x, params[x]);
  // });
  // console.log(formData);
  return request.post(Wishes, `api/banner/addWishes`, params);
}
export function getWishes(params: {wishId: number}): Promise<Result<Wishes>> {
  return request.get(Wishes, `/api/banner/getWishes/`, {params});
}
// 查询开屏页会员列表
export function selectWishes(params: {
  pageIndex: number;
  pageSize: number;
  sortDirection: string;
  phone?:string;
  id: number
}): Promise<Result<Page<Wishes>>> {
  return request.getPage(Wishes, `/api/banner/selectWishes/`, {params});
}
// 查询开屏页详情-编辑用
export function getWishesOperate(params: {id: number}): Promise<Result<WishesType>> {
  return request.get(WishesType, `/api/banner/getWishesOperate/`, {params});
}
// 更新开屏数据
export function updateWishes(params: {
  id:number,
  wishName:string,
  wishUrl: string,
  isAble: number,
  type: string,
  startTime: string,
  endTime: string,
  screenOpeningTime:number,
  linkUrl:string,
  status:number,
}) {
  return request.put(Wishes, '/api/banner/updateWishes', qs.stringify(params));
}
export function putWish(params: {
  wishId:number,
  // agentId: number,
  wishName:string,
  // companyId: number,
  wishUrl: string,
  isAble: number,
  type: string,
  linkUrl: string,
  status: number
}) {
  return request.put(Wishes, '/api/banner/updateWishes', qs.stringify(params));
}
// 删除开屏页分类
export function deleteWishesOperate(params: {id: number}): Promise<Result<void>> {
  return request.delete(`/api/banner/deleteWishesOperate/`, {params});
}
// 删除开屏页单个会员
export function deleteWish(params: {wishId: number}): Promise<Result<void>> {
  return request.delete(`/api/banner/deleteWishes/`, {params});
}
